import download from "@/api/download.js"

const state = {
	downloadList: []
}

const getters = {
	downloadList(state) {
		return state.downloadList;
	}
}

const actions = {
	getDownloadList({
		commit
	}, data) {
		return new Promise((resolve, reject) => {
			download.download(data).then((res) => {
				let code = res.data.code;
				if (code == 200) {
					commit('setDownloadState', {
							key: 'downloadList',
							value: res.data.data.data
						}),

						resolve(res)
				}
			}).catch((error) => {
				reject(error)
			});
		})
	},
}

const mutations = {
	setDownloadState(state, {
		key,
		value
	}) {
		state[key] = value
	},
}

export default {
	state,
	actions,
	mutations,
	getters,
	namespaced: true,
};